package com.bjwl.controller.safty;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bjwl.base.PageParams;
import com.bjwl.base.Result;
import com.bjwl.service.safty.UserService;
import com.bjwl.view.UserQueryView;
import com.github.pagehelper.PageInfo;

@RestController
@RequestMapping("/safty/user")
public class UserController {
	//声明业务对象
	@Autowired
	private UserService userService;
	
	
	//查询用户信息，全查，分页查询
	@GetMapping("/queryUser")
	public Map<String, Object> queryUser(PageParams pageParams){
		
		PageInfo<UserQueryView> users=userService.queryUser(pageParams);
		//创建一个Map集合
		Map<String, Object> map=new HashMap<>();
		map.put("total", users.getTotal());
		map.put("rows", users.getList());
		return map;
		
	}
	@PutMapping("/enableUser/{u_id}")
	public Result enableUser(@PathVariable String u_id) {
		boolean boo=userService.enableUser(u_id);
		if(boo==true) {
			//修改成功
			return Result.success(u_id+"用户已启用");
		}
		return Result.fail("系统升级中，启用失败");
		
	}
	@PutMapping("/disableUser/{u_id}")
	public Result disableUser(@PathVariable String u_id) {
		boolean boo=userService.disableUser(u_id);
		if(boo==true) {
			//修改成功
			return Result.success(u_id+"用户已禁用");
		}
		return Result.fail("系统升级中，禁用失败");
		
	}
	
	

}
